# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:xlwt_csv2xls.py
@Time:2022/3/15 7:41

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""
import xlwt


columns=[]
datas=[]
with open(r'..\data\0规上服务业财务月报2021年12月.csv','r',encoding='u8') as f:
    is_first_line=True
    for line in f:
        #line=line[:-2]
        # print(line)
        # columns=line.split(',')
        # columns=columns[:-1]
        # print(columns)
        if is_first_line:
            is_first_line=False
            columns=line.split(',')
            columns = columns[:-1]
            print(columns)
            continue
        line=line.split(',')[:-1]
        datas.append(line)
        # # datas=datas[:-1]
    #print(datas)

workbook=xlwt.Workbook(encoding='utf-8')
sheet=workbook.add_sheet('sheet1')

for col,column in enumerate(columns):
    sheet.write(0,col,column)
for row,data in enumerate(datas):
    for col,column_data in enumerate(data):
        sheet.write(row+1,col,column_data)
workbook.save(r'..\data\0规上服务业财务月报2021年12月.xls')
